n=int(input())
a=0
s=0
p=0
b=0
cont=0
if n<1000 or n>=10000:
    print(0)
else:
    for i in range(1,n+1):
        if n%i==0 :
            cont+=1
    if cont<10:
        if cont>2:
            for k in range(1,len(str(n))+1):
                s=(n//(10**k)%10)
                if i>1:
                      p=(n//(10**(k)))
                if s>b:
                     b=s
                if p>a:
                     a=p
        elif cont==2:
            print(n)
    else:
        print(0)
if a>b:
    print(a)
elif b>a:
    print(b)
